package com.roamer.school.shiro.util;

import com.roamer.school.common.Assert;
import org.apache.shiro.crypto.hash.SimpleHash;

/**
 * 编码器 工具类
 *
 * @author roamer
 * @version V1.0
 * @date 2019/1/20 18:34
 */
public abstract class CodecUtils {

    /** 加密算法 */
    public final static String DEFAULT_HASH_ALGORITHM_NAME = "MD5";

    /** 循环次数 */
    public final static int DEFAULT_HASH_ITERATIONS = 1024;

    /**
     * 将明文密码加盐后进行hash
     *
     * @param password 明文密码
     * @param salt     盐
     *
     * @return 加密后的密码
     *
     * @see org.apache.shiro.crypto.hash.SimpleHash
     */
    public static String encipher(String password, String salt) {
        Assert.hasText(password, "The password cannot be empty or null!");
        return new SimpleHash(DEFAULT_HASH_ALGORITHM_NAME, password, salt, DEFAULT_HASH_ITERATIONS).toString();
    }
}
